{include file="common/pc/header" title="数据库备份"/}

<style>
    #sending-info {
        margin-top: 12px;
    }
</style>

<!-- 上传 -->
<div class="container">
    <div class="layui-row layui-col-space20" id="salary-table">
        <div class='layui-col-xs10 layui-col-xs-offset1 add-item'>
            <table id="tables" lay-filter="tables"></table>
        </div>
    </div>
</div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="backup">开始备份</button>
    </div>
</script>

<script>
    var curBackupIndex = -1;
    var tablesInfo;
    var cols = [
        {type: 'checkbox', fixed: 'left'},
        {field: "id", title: "ID", width: 80, sort: true},
        {field: "state", title: "备份状态", sort: true},
        {field: "tablename", title: "数据表名称", sort: true},
        {field: "lineCount", title: "数据行数", sort: true},
    ];


    layui.use(['table', 'jquery'], function () {
        var table = layui.table;
        table.render({
            elem: '#tables'
            , url: 'tables'
            , toolbar: '#toolbar'
            , cols: [cols]
            , height: 'full-20'
            , done: function (res, curr, count) {
            }
        });

        //头工具栏事件
        table.on('toolbar(tables)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'backup':
                    tablesInfo = checkStatus.data;
                    if (tablesInfo.length <= 0) {
                        layer.msg('请先选择数据');
                    } else {
                        backupNext();
                    }
                    break;
            }
            ;
        });

    });

    function backupNext() {
        curBackupIndex++;
        if (curBackupIndex >= tablesInfo.length) {
            curBackupIndex = -1;
        } else {
            if (tablesInfo[curBackupIndex].state == '备份成功') {
                backupNext();
            } else {
                $.post(
                    "backupTable", {
                        'tablename': tablesInfo[curBackupIndex].tablename,
                        'ith': tablesInfo[curBackupIndex].id - 1,
                    }, function (res) {
                        select = 'table > tbody > tr:nth-child( ' + res.i + ') > td:nth-child(3)';
                        text = '<div class="layui-table-cell laytable-cell-1-0-2">' + res.state + '</div>';
                        $(select).html(text);
                        $(select).css('color', res.bg);
                        backupNext();
                    }
                );
            }
        }
    }
</script>

{include file="common/pc/footer"/}